package com.apkcore.core.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.apkcore.core.util.timetick.TimeTickScheduler

class TimeTickReceiver(private val scheduler: TimeTickScheduler) : BroadcastReceiver() {

    override fun onReceive(context: Context, intent: Intent) {
        if (Intent.ACTION_TIME_TICK == intent.action) {
            // 执行符合条件的任务
            scheduler.executeTasksIfNeeded(context)
        }
    }


    companion object {
        private const val TAG = "TimeTickReceiver"

//        private val timeTickReceiver by lazy { TimeTickReceiver(TimeTickScheduler.instance) }
//
//        fun register(context: Context) {
//            val filter = IntentFilter(Intent.ACTION_TIME_TICK)
//            context.registerReceiver(timeTickReceiver, filter)
//        }
//
//        fun unregister(context: Context) {
//            TimeTickScheduler.instance.release()
//            context.unregisterReceiver(timeTickReceiver)
//        }
    }
}
